import { NTag } from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
import GenerateHistoryTableDetail from './GenerateHistoryTableDetail.vue'
import type { ProjectGenerateHistoryVo } from '~/entity/project/project-generate-history-vo'

export const columns: DataTableColumns<ProjectGenerateHistoryVo> = [
  {
    title: '#',
    key: 'key',
    width: 50,
    align: 'center',
    render: (_, index) => index + 1,
  },
  {
    type: 'expand',
    width: 50,
    expandable: row => row.fileCount > 0,
    renderExpand: row => h(GenerateHistoryTableDetail, { historyId: row.id }),
  },
  {
    title: '方式',
    key: 'type',
    width: 80,
    align: 'center',
    render: (row) => {
      if (row.type === 1)
        return h(NTag, { type: 'success', size: 'small', bordered: false }, { default: () => '数据库表' })
      if (row.type === 2)
        return h(NTag, { type: 'info', size: 'small', bordered: false }, { default: () => '建表sql' })
    },
  },
  {
    title: '文件数',
    key: 'fileCount',
    width: 100,
    align: 'center',
  },
  {
    title: '项目链',
    key: 'no',
    width: 250,
    render: (row) => {
      return [row.project.name, row.template.name, row.develop.name].filter(item => item).join(' > ')
    },
  },
  {
    title: '标题',
    key: 'name',
    ellipsis: {
      tooltip: true,
    },
  },
  {
    title: '生成时间',
    key: 'gmtCreate',
    width: 180,
    align: 'center',
  },
  {
    title: '生成人',
    key: 'createUserName',
    width: 165,
    align: 'center',
  },
]
